<template>
  <el-dialog v-model="dialogTableVisible"
             title="科研详情"
             :close-on-click-modal="false"
             width="80%">
    <div>
      <el-form :model="form" label-width="auto" style="display: flex">
        <el-form-item label="开始时间" style=" padding-right: 20px">
          <el-date-picker
              v-model="form.startData"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="开始时间"
              style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
              v-model="form.endData"
              type="date"
              value-format="YYYY-MM-DD"
              placeholder="结束时间"
              style="width: 100%"
          />
        </el-form-item>
        <el-button type="primary" style="margin-left: 20px" @click="searchBtn">查询</el-button>
      </el-form>
    </div>
    <div  v-loading="loading" class="tables">
      <!--    代入数据-->
      <div v-if="list">
        <el-descriptions border>
          <el-descriptions-item label="姓名">{{ list.name }}</el-descriptions-item>
          <el-descriptions-item label="英文姓名">{{ list.nameEn }}</el-descriptions-item>
          <el-descriptions-item label="账号">{{ list.account }}</el-descriptions-item>
          <el-descriptions-item label="最后学位">{{ getEduLevelName(list.eduLevelId) }}</el-descriptions-item>
          <el-descriptions-item label="一级学科">{{ list.firstLevel }}</el-descriptions-item>
          <el-descriptions-item label="单位名称">{{ list.unitName }}</el-descriptions-item>
          <el-descriptions-item label="职称名称">{{ list.titleName }}</el-descriptions-item>
          <el-descriptions-item label="政治面貌">{{ list.polityName }}</el-descriptions-item>
          <el-descriptions-item label="科学研究领域">{{ list.searchName }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <!--      //纵向项目立项-->
      <div v-if="zxxmlx && zxxmlx.length > 0">
        <div class="">纵向项目立项</div>
        <el-table :data="zxxmlx" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="code" label="项目编号"></el-table-column>
          <el-table-column prop="proName" label="项目名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openProjcet(row)">{{ row.proName }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="feeAuthorize" label="项目总经费（万元）">
            <template #default="{ row }">
              {{ row.feeAuthorize }}
            </template>
          </el-table-column>
          <el-table-column prop="authorizeDate" label="项目立项"></el-table-column>
          <el-table-column prop="projectTypeName" label="项目分类">
            <template #default="{ row, $index }">
              {{ getProjectTypeNameZX(row.projectTypeCode) }}
            </template>

          </el-table-column>
          <el-table-column prop="unitName" label="所属单位"></el-table-column>
        </el-table>
      </div>
      <!--      //进账合同签订-->
      <div v-if="jzhtqd && jzhtqd.length > 0">
        <div class="">进账合同签订</div>
        <el-table :data="jzhtqd" border>
          <el-table-column label="序号"width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="code" label="合同编号"></el-table-column>
          <el-table-column label="合同名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openProjcet(row)">{{ row.proName }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="beginDate" label="开始日期">
            <template #default="{ row }">
              {{handleTime(row.beginDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="planEndDate" label="结束日期">
            <template #default="{ row }">
              {{handleTime(row.planEndDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="projectTypeName" label="合同类别">
            <template #default="{ row, $index }">
              {{ getProjectTypeNameHX(row.projectTypeCode) }}
            </template>
          </el-table-column>

        </el-table>
      </div>
      <!--      //校级项目立项-->
      <div v-if="xjxmlx && xjxmlx.length > 0">
        <div class="">校级项目立项</div>
        <el-table :data="xjxmlx" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="proName" label="项目名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openProjcet(row)">{{ row.proName }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="chargerName" label="负责人姓名"></el-table-column>
          <el-table-column prop="feeAuthorize" label="批准经费（万元）">
            <template #default="{ row }">
              {{ row.feeAuthorize }}
            </template>
          </el-table-column>
          <el-table-column prop="authorizeDate" label="立项日期">
            <template #default="{ row }">
              {{handleTime(row.authorizeDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="projectTypeName" label="项目分类">
            <template #default="{ row, $index }">
              {{ getProjectTypeNameXJ(row.projectTypeCode) }}
            </template>
          </el-table-column>
          <el-table-column prop="unitName" label="所属单位"></el-table-column>
        </el-table>
      </div>
      <!--      //纵向项目到账-->
      <div v-if="zxxmdz && zxxmdz.length > 0">
        <div class="">纵向项目到账</div>
        <el-table :data="zxxmdz" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="projectCode" label="项目编号"></el-table-column>
          <el-table-column prop="projectName" label="项目名称"></el-table-column>
          <el-table-column prop="chargerName" label="负责人姓名"></el-table-column>
          <el-table-column prop="claimFee" label="申请金额（万元）">
            <template #default="{ row }">
              {{ turnWanyuan(row.claimFee) }}
            </template>
          </el-table-column>
          <el-table-column prop="schoolFee" label="学校经费（万元）">
            <template #default="{ row }">
                {{ turnWanyuan(row.schoolFee) }}
            </template>
          </el-table-column>
          <el-table-column prop="outboundFee" label="外拨经费（万元）">
            <template #default="{ row }">
              {{ turnWanyuan(row.outboundFee) }}
            </template>
          </el-table-column>
          <el-table-column prop="claimDate" label="申请日期">
            <template #default="{ row }">
              {{handleTime(row.claimDate)}}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--      //乙方合同到账-->
      <div v-if="yfhtdz && yfhtdz.length > 0">
        <div class="">乙方合同到账</div>
        <el-table :data="yfhtdz" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="projectCode" label="项目编号"></el-table-column>
          <el-table-column prop="projectName" label="项目名称"></el-table-column>
          <el-table-column prop="feeAuthorize" label="合同金额（万元）">
            <template #default="{ row }">
              {{ turnWanyuan(row.feeAuthorize) }}
            </template>
          </el-table-column>
          <el-table-column prop="incomeUnit" label="来款单位"></el-table-column>
          <el-table-column  prop="checkstatus" label="审核状态">
            <template #default="{ row }">
              <CommonLabel
                  :dataList="checkStatusList"
                  valueKey="dictValue"
                  labelKey="dictLabel"
                  :value="row.checkstatus"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--      //校级项目到账-->
      <div v-if="xjxmdz && xjxmdz.length > 0">
        <div class="">校级项目到账</div>
        <el-table :data="xjxmdz" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="projectCode" label="项目编号"></el-table-column>
          <el-table-column prop="projectName" label="项目名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openProjcet(row)">{{ row.projectName }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="projectTypeName" label="项目分类"></el-table-column>
          <el-table-column prop="feeAuthorize" label="合同金额（万元）">
            <template #default="{ row }">
              {{ turnWanyuan(row.feeAuthorize) }}
            </template>
          </el-table-column>
          <el-table-column prop="claimFee" label="本次入账（万元）">
            <template #default="{ row }">
              {{ turnWanyuan(row.claimFee) }}
            </template>
          </el-table-column>
          <el-table-column prop="incomeUnit" label="来款单位"></el-table-column>
        </el-table>
      </div>
      <!--      //标准-->
      <div v-if="standard && standard.length > 0">
        <div class="">标准</div>
        <el-table :data="standard" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="标准名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'standard')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="code" label="标准编号"></el-table-column>
          <el-table-column prop="typeId" label="标准类别"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="checkstatus" label="审核状态"></el-table-column>
          <el-table-column prop="submitDate" label="提交日期">
            <template #default="{ row }">
              {{handleTime(row.submitDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="note" label="备注"></el-table-column>
        </el-table>
      </div>
      <!--      //专利-->
      <div v-if="patent && patent.length > 0">
        <div class="">专利</div>
        <el-table :data="patent" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="专利名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'patent')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="typeId" label="专利类型"></el-table-column>
          <el-table-column prop="applyInfo" label="申请人"></el-table-column>
          <el-table-column prop="applyDate" label="申请日期">
            <template #default="{ row }">
              {{handleTime(row.applyDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="stateId" label="专利状态"></el-table-column>
          <el-table-column prop="applyInfo" label="专利权人"></el-table-column>

        </el-table>
      </div>
      <!--      //药证-->
      <div v-if="medicine && medicine.length > 0">
        <div class="">药证</div>
        <el-table :data="medicine" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="药证名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'medicine')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="typeId" label="药证分类"></el-table-column>
<!--          <el-table-column prop="subjectId" label="一级学科"></el-table-column>-->
          <el-table-column prop="checkstatus" label="审核状态"></el-table-column>
        </el-table>
      </div>
      <!--      //著作权-->
      <div v-if="copyRight && copyRight.length > 0">
        <div class="">著作权</div>
        <el-table :data="copyRight" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="著作权名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'copyRight')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="typeId" label="著作类别"></el-table-column>
          <el-table-column prop="publicationDate" label="出版时间">
            <template #default="{ row }">
              {{handleTime(row.publicationDate)}}
            </template>

          </el-table-column>
          <el-table-column prop="authornames" label="所有作者"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>


        </el-table>
      </div>
      <!--      //新品种-->
      <div v-if="breed && breed.length > 0">
        <div class="">新品种</div>
        <el-table :data="breed" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="新品种名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'breed')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="firstAuthorName" label="第一完成人姓名"></el-table-column>
          <el-table-column prop="authorizeUnit" label="审定单位"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="authorizeDate" label="审定日期">
            <template #default="{ row }">
              {{handleTime(row.authorizeDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="checkstatus" label="审核状态"></el-table-column>
        </el-table>
      </div>
      <!--      //科研转化成果-->
      <div v-if="productTransform && productTransform.length > 0">
        <div class="">科研转化成果</div>
        <el-table :data="productTransform" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="code" label="知识产权编号"></el-table-column>
          <el-table-column prop="name" label="成果名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'productTransform')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="typeId" label="知识产权类型"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="txAuthor" label="成果联系人"></el-table-column>
          <el-table-column prop="txAuthorTel" label="联系人电话"></el-table-column>
          <el-table-column prop="firstAuthorName" label="第一完成人"></el-table-column>
          <el-table-column prop="authorTel" label="完成人电话"></el-table-column>
          <el-table-column prop="researchDate" label="研发起止时间">
<!--            <template #default="{ row }">-->
<!--              {{handleTime(row.researchDate)}}-->
<!--            </template>-->
          </el-table-column>
          <el-table-column prop="checkstatus" label="审核状态"></el-table-column>
        </el-table>
      </div>
      <!--      //艺术作品-->
      <div v-if="artProduct && artProduct.length > 0">
        <div class="">艺术作品</div>
        <el-table :data="artProduct" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="艺术作品名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'artProduct')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="firstAuthorName" label="第一完成人姓名"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="typeId" label="作品类型"></el-table-column>
          <el-table-column  prop="checkstatus" label="审核状态">
            <template #default="{ row }">
              <CommonLabel
                  :dataList="checkStatusList"
                  valueKey="dictValue"
                  labelKey="dictLabel"
                  :value="row.checkstatus"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--      //研究报告-->
      <div v-if="researchReport && researchReport.length > 0">
        <div class="">研究报告</div>
        <el-table :data="researchReport" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="研究报告名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'researchReport')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="submitDate" label="提交日期">
            <template #default="{ row }">
              {{handleTime(row.submitDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="acceptObject" label="采纳对象"></el-table-column>
          <el-table-column prop="authornames" label="所有完成人"></el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
        </el-table>
      </div>
      <!--      //成果评价-->
      <div v-if="appraisalProduct && appraisalProduct.length > 0">
        <div class="">成果评价</div>
        <el-table :data="appraisalProduct" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="成果名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'appraisalProduct')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column  prop="checkstatus" label="审核状态">
            <template #default="{ row }">
              <CommonLabel
                  :dataList="checkStatusList"
                  valueKey="dictValue"
                  labelKey="dictLabel"
                  :value="row.checkstatus"
              />
            </template>
          </el-table-column>
          <el-table-column prop="unitId" label="所属单位"></el-table-column>
          <el-table-column prop="completeUnits" label="完成单位"></el-table-column>
          <el-table-column prop="authornames" label="所有完成人"></el-table-column>
        </el-table>
      </div>
      <!--      //论文-->
      <div v-if="paper && paper.length > 0">
        <div class="">论文</div>
        <el-table :data="paper" border>
          <el-table-column label="序号" width="60">
            <template #default="{ row, $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="name" label="论文名称">
            <template #default="{ row }">
              <div style="cursor: pointer;color: #2A91FE">
                <span @click="openModelVisible(row,'paper')">{{ row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="publishDate" label="发表/出版时间">
            <template #default="{ row }">
              {{handleTime(row.publishDate)}}
            </template>
          </el-table-column>
          <el-table-column prop="magazineName" label="发表/刊物论文集"></el-table-column>
          <el-table-column label="所属单位">
            <template #default="{ row }">
              {{ getUnitName(row.unitId) }}
            </template>
          </el-table-column>
          <el-table-column prop="firstAuthorName" label="获取论文第一作者"></el-table-column>

        </el-table>
      </div>
    </div>
  </el-dialog>


  <ViewProject ref="viewProjectRef" />
  <achievementPreview v-model="ModelVisible" :id="achievementPreviewId" :type="achievementPreviewTYPE" />
</template>


<script setup lang="ts">
import {ref} from "vue";

const loading = ref(false) // 添加加载状态
import {
  turnWanyuan
} from '@/utils/money'

//项目分类
const projectTypeCodeoptionHX = ref('')
const getprojectTypeCodeoptionHX = () => {

  getCategory(
      {
        'bizName':'项目分类（横向）'
      }
  )
      .then((res)=>{
        projectTypeCodeoptionHX.value = res.data
      })

  //return eduLevelMap[eduLevelId] || '未知';
};
const getProjectTypeNameHX = (projectTypeCode: number): string => {
  const label = findLabelInTree(projectTypeCodeoptionHX.value, projectTypeCode)
  return label || '未知'
}
//项目分类
const projectTypeCodeoptionZX = ref('')
const getprojectTypeCodeoptionZX = () => {

  getCategory(
      {
        'bizName':'项目分类（纵向）'
      }
  )
      .then((res)=>{
        projectTypeCodeoptionZX.value = res.data
      })

  //return eduLevelMap[eduLevelId] || '未知';
};
// 根据 projectTypeCode 获取项目分类名称
const getProjectTypeNameZX = (projectTypeCode: number): string => {
  const label = findLabelInTree(projectTypeCodeoptionZX.value, projectTypeCode)
  return label || '未知'
}
//项目分类
const projectTypeCodeoptionXJ = ref('')
const getprojectTypeCodeoptionXJ = () => {

  getCategory(
      {
        'bizName':'项目分类（校级）'
      }
  )
      .then((res)=>{
        projectTypeCodeoptionXJ.value = res.data
      })

  //return eduLevelMap[eduLevelId] || '未知';
};
// 根据 projectTypeCode 获取项目分类名称
const getProjectTypeNameXJ = (projectTypeCode: number): string => {
  const label = findLabelInTree(projectTypeCodeoptionXJ.value, projectTypeCode)
  return label || '未知'
}
// 递归查找树形结构中的匹配项
const findLabelInTree = (tree: any[], id: number): string | null => {
  for (const node of tree) {
    if (node.id === id) {
      return node.label
    }
    if (node.children && node.children.length > 0) {
      const found = findLabelInTree(node.children, id)
      if (found) {
        return found
      }
    }
  }
  return null
}





//最后学位
const getEduLevelName = (eduLevelId) => {
  if (eduLevelId === undefined || eduLevelId == null) {
    return '未知';
  }
  const eduLevelMap = {
    3: '大专',
    4: '中专',
    0: '博士研究生',
    1: '硕士研究生',
    2: '本科',
    5: '其他'
  };
  return eduLevelMap[eduLevelId] || '未知';
};

//成果
import achievementPreview from "@/components/achievementPreview/index.vue"
const ModelVisible = ref(false)
const achievementPreviewId = ref()//成果id
const achievementPreviewTYPE = ref()//成果类型
const openModelVisible = (row: any, type: string) => {
  if (row.id === null) {
    ElMessage({
      message: '没有row.id',
      type: 'warning',
    });
  } else {
    achievementPreviewTYPE.value = type;
    achievementPreviewId.value = row.id;
    // console.log(achievementPreviewTYPE.value, achievementPreviewId.value)
    ModelVisible.value = true;
  }
};
//项目详情
import ViewProject from "@/views/project/components/ViewProject";
const viewProjectRef = ref(null);
const openProjcet = (row) => {
  const targetClass = row.proClass || row.projectClass;
  viewProjectRef.value.view(row.id,targetClass);
};

import CommonLabel from "@/views/project/components/CommonLabel.vue";
import useDictFetch from "@/hooks/useDictFetch";
const checkStatusList = useDictFetch("bpm_process_instance_status"); //审核状态
import {
  personCheck,
  getCategory
} from './../../api/researcherNavApi/researcherNavApi'
import {ElMessage} from "element-plus";

// do not use same name with ref
const form = ref({
  startData: '',
  endData: '',
})

const list = ref(null) //信息
const zxxmlx =ref(null) //纵向项目立项
const jzhtqd =ref(null) //进账合同签订
const xjxmlx =ref(null) //校级项目立项
const zxxmdz =ref(null) //纵向项目到账
const yfhtdz =ref(null) //乙方合同到账
const xjxmdz =ref(null) //校级项目到账
const standard =ref(null) //标准
const patent =ref(null) //专利
const medicine =ref(null) //药证
const copyRight =ref(null) //著作权
const breed =ref(null) //新品种
const productTransform =ref(null) //科研转化成果
const artProduct =ref([]) //艺术作品
const researchReport =ref(null) //科研转化成果
const appraisalProduct =ref(null) //成果评价
const paper =ref(null) // 论文
/**
 *  * medicine 药证
 *  * patent 专利
 *  * productTransform 科研转化成果
 *  * list  信息
 *  * standard 标准
 *  * copyRight 著作权
 *  * breed 新品种
 *  * xjxmdz 校级项目到账
 *  * xjxmlx 校级项目立项
 *  * yfhtdz 乙方合同到账
 *  * jzhtqd 进账合同签订
 *  * zxxmdz 纵向项目到账
 *  * zxxmlx 纵向项目立项
 *  *artProduct 艺术作品
 *  *researchReport 科研转化成果
 *  *appraisalProduct 成果评价
 *  *paper 论文
 */
// 定义一个函数来处理时间字符串
function handleTime(timeStr) {
  const date = new Date(timeStr);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}
    // 根据单位ID获取单位名称的方法
const getUnitName = (unitId) => {
      const option = shuoshudanweiOptions.value.find(option => option.codeColumn === unitId);
      return option ? option.valueColumn : unitId;
    }
//所属单位
const shuoshudanweiOptions = ref([])

const getshuoshudanweiOptions =function () {
  getCategory(
      {
        'bizName':'成果归属单位'
      }
  )
      .then((res)=>{

        shuoshudanweiOptions.value = res.data
      })
}



const dialogTableVisible = ref(false)

const rowids = ref('')

const searchBtn = function (){
  clearData(); // 清空数据
  personCheck({
    id:rowids.value,
    createdate:form.value.startData || '',
    lastdate:form.value.endData || '',
  })
      .then((res)=>{
        if (res.data && res.data.list && res.data.list.length > 0) {
          list.value = res.data.list[0];
        }
        if (res.data && res.data.zxxmlx && res.data.zxxmlx.length > 0) {
          zxxmlx.value = res.data.zxxmlx;
        }
        if (res.data && res.data.jzhtqd && res.data.jzhtqd.length > 0) {
          jzhtqd.value = res.data.jzhtqd;
        }
        if (res.data && res.data.xjxmlx && res.data.xjxmlx.length > 0) {
          xjxmlx.value = res.data.xjxmlx;
        }
        if (res.data && res.data.zxxmdz && res.data.zxxmdz.length > 0) {
          zxxmdz.value = res.data.zxxmdz;
        }
        if (res.data && res.data.yfhtdz && res.data.yfhtdz.length > 0) {
          yfhtdz.value = res.data.yfhtdz;
        }
        if (res.data && res.data.xjxmdz && res.data.xjxmdz.length > 0) {
          xjxmdz.value = res.data.xjxmdz;
        }
        if (res.data && res.data.standard && res.data.standard.length > 0) {
          standard.value = res.data.standard;
        }
        if (res.data && res.data.patent && res.data.patent.length > 0) {
          patent.value = res.data.patent;
        }
        if (res.data && res.data.medicine && res.data.medicine.length > 0) {
          medicine.value = res.data.medicine;
        }
        if (res.data && res.data.copyRight && res.data.copyRight.length > 0) {
          copyRight.value = res.data.copyRight;
        }
        if (res.data && res.data.breed && res.data.breed.length > 0) {
          breed.value = res.data.breed;
        }
        if (res.data && res.data.productTransform && res.data.productTransform.length > 0) {
          productTransform.value = res.data.productTransform;
        }
        if (res.data && res.data.artProduct && res.data.artProduct.length > 0) {
          artProduct.value = res.data.artProduct;
        }
        if (res.data && res.data.researchReport && res.data.researchReport.length > 0) {
          researchReport.value = res.data.researchReport;
        }
        if (res.data && res.data.appraisalProduct && res.data.appraisalProduct.length > 0) {
          appraisalProduct.value = res.data.appraisalProduct;
        }
        if (res.data && res.data.paper && res.data.paper.length > 0) {
          paper.value = res.data.paper;
        }
        getshuoshudanweiOptions();
        getprojectTypeCodeoptionXJ()
        getprojectTypeCodeoptionZX()
        getprojectTypeCodeoptionHX()
      })
}
// 清空数据的函数
const clearData = () => {
  list.value = null;
  zxxmlx.value = null;
  jzhtqd.value = null;
  xjxmlx.value = null;
  zxxmdz.value = null;
  yfhtdz.value = null;
  xjxmdz.value = null;
  standard.value = null;
  patent.value = null;
  medicine.value = null;
  copyRight.value = null;
  breed.value = null;
  productTransform.value = null;
  artProduct.value = [];
  researchReport.value = null;
  appraisalProduct.value = null;
  paper.value = null;
};
const openDialogDetailsPage = function (rowid){
  rowids.value = rowid
  if(!rowid){
    ElMessage({
      message: '没有成员Id',
      type: 'warning',
    })
    return
  }else {
    dialogTableVisible.value = true
    loading.value = true
    clearData(); // 清空数据
    personCheck({
      id:rowid,
      createdate:form.value.startData,
      lastdate:form.value.endData
    })
        .then((res)=>{
          if (res.data && res.data.list && res.data.list.length > 0) {
            list.value = res.data.list[0];
          }
          if (res.data && res.data.zxxmlx && res.data.zxxmlx.length > 0) {
            zxxmlx.value = res.data.zxxmlx;
          }
          if (res.data && res.data.jzhtqd && res.data.jzhtqd.length > 0) {
            jzhtqd.value = res.data.jzhtqd;
          }
          if (res.data && res.data.xjxmlx && res.data.xjxmlx.length > 0) {
            xjxmlx.value = res.data.xjxmlx;
          }
          if (res.data && res.data.zxxmdz && res.data.zxxmdz.length > 0) {
            zxxmdz.value = res.data.zxxmdz;
          }
          if (res.data && res.data.yfhtdz && res.data.yfhtdz.length > 0) {
            yfhtdz.value = res.data.yfhtdz;
          }
          if (res.data && res.data.xjxmdz && res.data.xjxmdz.length > 0) {
            xjxmdz.value = res.data.xjxmdz;
          }
          if (res.data && res.data.standard && res.data.standard.length > 0) {
            standard.value = res.data.standard;
          }
          if (res.data && res.data.patent && res.data.patent.length > 0) {
            patent.value = res.data.patent;
          }
          if (res.data && res.data.medicine && res.data.medicine.length > 0) {
            medicine.value = res.data.medicine;
          }
          if (res.data && res.data.copyRight && res.data.copyRight.length > 0) {
            copyRight.value = res.data.copyRight;
          }
          if (res.data && res.data.breed && res.data.breed.length > 0) {
            breed.value = res.data.breed;
          }
          if (res.data && res.data.productTransform && res.data.productTransform.length > 0) {
            productTransform.value = res.data.productTransform;
          }
          if (res.data && res.data.artProduct && res.data.artProduct.length > 0) {
            artProduct.value = res.data.artProduct;
          }
          if (res.data && res.data.researchReport && res.data.researchReport.length > 0) {
            researchReport.value = res.data.researchReport;
          }
          if (res.data && res.data.appraisalProduct && res.data.appraisalProduct.length > 0) {
            appraisalProduct.value = res.data.appraisalProduct;
          }
          if (res.data && res.data.paper && res.data.paper.length > 0) {
            paper.value = res.data.paper;
          }
          getshuoshudanweiOptions();
          getprojectTypeCodeoptionXJ()
          getprojectTypeCodeoptionZX()
          getprojectTypeCodeoptionHX()
        })
        .finally(() => {
          loading.value = false // 结束加载
        })
  }


}

defineExpose({
  openDialogDetailsPage
})
</script>

<style scoped lang="scss">
.tables > div > div:first-child{
  font-size: 16px;
  color: black;
  font-weight: bolder;
  margin: 10px 0;
}

</style>